package fatworm.query;

import fatworm.query.constant.Constant;

public class ProductScan implements Scan {
	
	private Scan s1, s2;
	
	public ProductScan(Scan s1, Scan s2) {
		this.s1 = s1;
		this.s2 = s2;
		s1.next();
	}
	public void beforeFirst() {
		s1.beforeFirst();
		s1.next();
		s2.beforeFirst();
	}
	
	public boolean next() {
		if (s2.next())
			return true;
		
		s2.beforeFirst();
		if (s1.next())
			return s2.next();
		else
			return false;
	}
	
	public void close() {
		s1.close();
		s2.close();
	}
	
	public Constant getVal(String name) {
		if (s1.hasField(name)) 
			return s1.getVal(name);
		else
			return s2.getVal(name);
	}
	
/*	public int getInt(String name) {
		if (s1.hasField(name)) 
			return s1.getInt(name);
		else
			return s2.getInt(name);
	}
	
	public String getString(String name) {
		if (s1.hasField(name))
			return s1.getString(name);
		else
			return s2.getString(name);
	}*/
	
	public boolean hasField(String name) {
		return s1.hasField(name) || s2.hasField(name);
	}
}